<link rel="stylesheet" type="text/css" href="{{ URL::asset('public_css/base.css') }}" />
@include('new.newheader')
<link rel="stylesheet" type="text/css" href="{{ URL::asset('newpay/css/newpay.css') }}" />
<script src="{{ URL::asset('public_js/jquery-3.2.1.min.js') }}"></script>
<script src="{{URL::asset('public_js/distpicker.data.js')}}"></script>
<script src="{{URL::asset('public_js/distpicker.js')}}"></script>
<div class="J_pay">
	<p style="font-size:14px;">
		当前位置
		<span>充值>付款</span>
	</p>
</div>
	
<div class="J_pay_content">
	<div class="J_pay_text" style="width:90%;margin:0 auto;float: none;">
		<div class="J_pay_title" style="padding-top: 25px;">
			<p style="font-size:20px;color: #141414;">收货地址</p>
		</div>
		<div class="J_message">
			<div class="J_tel">
				收货人
				<input type="text" placeholder="请输入收货人姓名" id="name" >
			</div>
			<div class="J_tel">
				手机号
				<input type="text" placeholder="请输入收货人手机号码" id="tel" >
			</div>
			<div class="J_tel">
				<div data-toggle="distpicker" class="j_select" style="display: inline-block;">
					<span>所在地</span>
					<select id="province"  data-province=""></select>
					<select id="city" data-city=""></select>
					<select id="country" data-district=""></select>
					<input type="text" placeholder="请输入详细地址" id="details" >
				</div>
			</div>
		</div>
		<div class="J_dingdan" style="padding-top:0px;">
			<div class="J_dingdan_list">
				<img src="{{ URL::asset('newpay/image/minchangping.png') }}" alt="">
				<span>EAI2.0 &nbsp; 大数据智能跟单系统 &nbsp; {{$buyMonth}}个月 <span>￥{{$cpMoney}}</span></span>
			</div>
			<div style="height: 8px;"></div>
			@if($buyVpsMoney != 0)
				<div class="J_dingdan_list">
					<img src="{{ URL::asset('newpay/image/min_qinglv.png') }}" alt="">
					<span>EAI2.0 &nbsp; 大数据智能跟单系统伴侣 &nbsp; {{$buyMonth}}个月 <span>￥{{$buyVpsMoney}}</span></span>
				</div>
			@endif
		</div>
        <div style="height: 8px;"></div>
		<div class="J_jiesuan" style="height: 140px;">
			<p>优惠金额 <span>￥{{$yhMoney}}</span></p>
			<p>快递     <span><s>￥20.00</s>￥0.00</span></p>
			<p style="line-height: 60px;color: #ff5475;font-size: 15px;">
				总计
				<span style="font-size: 20px;"><s style="font-size: 14px;">￥{{$allMoney}}</s>￥{{$totalMoney}}</span>
			</p>
		</div>
		<h1 class="J_xzzf">选择支付方式</h1>
		<div class="zhifukuan">
			<p>支付平台</p>
			<span>
				<img src="{{ URL::asset('newpay/image/event-alipay.png') }}" alt="" onclick="pay(1,this)">
			</span>
			<span>
				<img src="{{ URL::asset('newpay/image/weixinpay.png') }}" alt="" onclick="pay(0,this)">
			</span>
		</div>
		{{--<div class="J_tijiao" style="margin-top:30px;margin-left: 42%;" id="subBtnPayment">--}}
			{{--付款--}}
		{{--</div>--}}
	</div>
	<div style="clear: both;height: 180px;"></div>
</div>
<div id="mask"></div>
<div class="zhifutan">
	<div class="zhifutitle">
		<span>收款方：毅思科技</span>
		<span class="J_close"><img style="margin-top: 18px;" src="{{URL::asset('images/close.png')}}"></span>
	</div>
	<div class="J_conTitle">
		<span>支付宝扫一扫</span>
		<div class="erweima">
			<img src="{{ URL::asset('newpay/image/erweima.png') }}" alt="">
		</div>
	</div>
</div>
<div class="zf_msg">
	<div class="loadEffect">
		<span></span>
		<span></span>
		<span></span>
		<span></span>
		<span></span>
		<span></span>
		<span></span>
		<span></span>
	</div>
</div>
<div id="tanCeng">
	<span></span>
	<a href='/authenticate?id=tiyan' style='cursor:pointer;color:#3b9ce0;'>
		<button onclick="perfectInfo()" style="display:none;">完善资料</button>
	</a>
</div>
<script src="{{ URL::asset('public_js/jquery-3.2.1.min.js') }}"></script>
<script>
	//验证支付是否成功
   function isPaySuccess(orderNo){
		var returnUrl="{{url('/paysuccess')}}";
		if(orderNo==null){
				return false;
		}else{
			$.ajax({
				url:"checkpayresult", //验证支付是否成功
				type:'post',
				data:{'orderid':orderNo},
				headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
				dataType:'json',
				success:function(data){
					if(data.type != -2){ //代表错误
							if(data.status == 2 || data.status == 3 || data.status == 4){ //支付成功
								window.location.href=returnUrl+'?orderid='+orderNo;
							}
					}else{
						window.location.href=returnUrl+'?orderid=0';
					}
				}
			});
		}
   }

	//点击付款
	function pay(genre,obj) {
		$(obj).removeAttr('onclick');
		var islogin = "<?php echo Session('eai')['tel']?>";
		if(!islogin){
			showCeng();
			$('#tanCeng>a>button').hide();
			$("#tanCeng").css({'width':'250px','height':'80px','line-height':'80px'}).html('请先<a href="{{ url('/login') }}" style="cursor:pointer;color:#3b9ce0;font-size: 20px;">登录</a>！');
			return false;
		}
		var khName 		= $.trim($('#name').val()),   		// 客户的用户名
			khTel  		= $.trim($('#tel').val()),          // 客户的手机号
			khProvince	= $.trim($('#province option:selected').val()),     // 省
			khCity		= $.trim($('#city option:selected').val()),         // 市
			khCountry	= $.trim($('#country option:selected').val()),      // 区
			khDetails	= $.trim($('#details').val());      // 详细地址
		var yhMonth     = '{{$buyMonth}}';//选中的月份
		var isbuyvps    = '{{$isBuyVps}}';
		var aisyh       = '{{$isYh}}';
		var nameReg = /^[\u4e00-\u9fffa-zA-Z]{2,6}$/;
		if(khName === '' || !(nameReg.test(khName))){
			layer.msg('请输入正确的姓名');
			$(obj).attr('onclick','pay('+genre+',this)');
			return false;
		}
		if(!(/^(13|14|15|17|18)\d{9}$/.test(khTel))){
			layer.msg('请输入正确的手机号');
			$(obj).attr('onclick','pay('+genre+',this)');
			return false;
		}
		if(khDetails == ''){
			layer.msg('请输入详细地址');
			$(obj).attr('onclick','pay('+genre+',this)');
			return false;
		}
		//提示loading
		$('#mask').show();
		$('.zf_msg').show();
		$.ajax({
			type: 'post',
			url:"{{url('/addpay')}}",
			data:{
				'isYH':aisyh,
				'yhMonth':yhMonth,
				'isbuyvps':isbuyvps,
				'khName':khName,
				'khTel':khTel,
				'khProvince':khProvince,
				'khCity':khCity,
				'khCountry':khCountry,
				'khDetails':khDetails,
				'type':genre
			},
			dataType: "json",
			headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
			timeout : 3000,//超时设置
			success:function(data){
				$('#mask').hide();
				$('.zf_msg').hide();
				if(data.status == 2){  // 成功以后跳转
					$('#mask').show();
					$('.zhifutan').show();
					if(genre == 1){
						$('.J_conTitle span').text('支付宝扫一扫');
					}else{
						$('.J_conTitle span').text('微信扫一扫');
					}
					$('.erweima img').attr('src',data.qrcode);
					setInterval(function () {
						isPaySuccess(data.orderid);
					},3000);
					$(obj).attr('onclick','pay('+genre+',this)');
				}else if(data.status == 0){
					layer.msg("请先<a href='{{ url("/login") }}' style='cursor:pointer;color:#3b9ce0;font-size: 20px;'>登录</a>！");
					return false;
				}else{
					$(obj).attr('onclick','pay('+genre+',this)');
					layer.msg(data.msg);
					return false;
				}
			},
			error:function(xhr,textStatus){
				$('#mask').hide();
				$('.zf_msg').hide();
				if(textStatus=='timeout'){
					//处理超时的逻辑
					$(obj).attr('onclick','pay('+genre+',this)');
					layer.msg('网络超时请重新操作！');
					return false;
				}
			}
		})
	}
	$('.J_close').click(function(){
		$('.zf_msg').hide();
		$('.zhifutan').hide();
		$('#mask').hide();
	});
	//提示层
	function showCeng(){
		var div_mask=$('#mask');
		var width=document.body.scrollWidth+'px';
		var height=document.body.scrollHeight+'px';
		div_mask.css({'width':width,'height':height,'display':'block'});
		$('#mask').show();
		$("#tanCeng").show();
	}
</script>
